package middleware.p2p.global.logger;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.jws.WebService;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import middleware.p2p.log.MiddlewareLogEvent;

/**
 * Session Bean implementation class GlobalLogger
 */
@Stateless
@WebService(name="GlobalLogger", serviceName="GlobalLoggerService")
public class GlobalLogger implements GlobalLoggerRemote {
	@EJB(name="ejb/LogQueue",beanInterface=middleware.p2p.global.logger.EventQueueManagerLocal.class)
	private EventQueueManagerLocal queue;
    /**
     * Default constructor. 
     */
    public GlobalLogger() {
    	super();
		try {
	        Context ctx = new InitialContext();
			this.queue = (EventQueueManagerLocal)ctx.lookup("java:comp/env/ejb/LogQueue");
		} catch (NamingException e) {
			e.printStackTrace();
		}        
    }

	@Override
	@TransactionAttribute(TransactionAttributeType.NEVER)
	public boolean push(MiddlewareLogEvent event) {		
		return queue.enqueue(event);
		
	}

	@Override
	public boolean resetLoggingSession(String componentId) {
		this.queue.resetQueue(componentId);
		return true;
	}	
}
